package org.niu.listnode;

public class HasCircle {
    public boolean hasCycle(ListNode head) {
        if(head == null) return false;
        //if(head.next!=null&&head.next==head) return true;
        //if(head.next.next==head) return true;
        if(head.next==null) return false;
        if(head.next.next == null) return false;
        ListNode fast = head,slow = head;
        fast = fast.next;
        while(fast.next.next!=null && fast!=slow){
            fast = fast.next.next;
            slow = slow.next;
        }
        if(fast==slow) return true;
        return false;
    }
}
